<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>简单秒表</title>
		<!-- 2:实现类似田径比赛上的计时功能，
点击 开始 按钮开始计时，点击  结束按钮 停止及时，
同时页面上显示计时的秒数（以0.01秒为最小间隔单位）
 -->
		<style>
			#main{
				width: 200px;
				height: 100px;
				line-height: 100px;
				text-align: center;
				margin: auto auto;
				border: 1px solid black;
				font-size: 20px;
				font-weight: 900;
			}
			#bottom{
				margin: auto;
				width: 100px;
			}
			
		</style>
	</head>
	<body>
		<div id="main">
			<span>00</span>
			<span>:</span>
			<span>0.00</span>
			
		</div>
		<div id="bottom">
			<button type="button" onclick="start()">开始</button>
			<button type="button" onclick="window.clearInterval(timer)">停止</button>
		</div>
		
		
		<script>
			var second=0;
			var min=0;
			var main=document.getElementById("main");
			//声明定时器
			var timer;
			
			function start(){
				window.clearInterval(timer);
				 timer=window.setInterval(function start(){
					second+=0.01;
					// alert(second.toFixed(0)%60);
					if(second.toFixed(0)==60){
						main.children[2].innerHTML="0.00";
						min++;
						main.children[0].innerHTML=(min>=10?min:"0"+min);
						//秒数归零
						second=0;
					}
					main.children[2].innerHTML=second.toFixed(2);
					
				},10);
			}
			
		</script>
	</body>
</html>